package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.pojo.Courier;
import com.sky.pojo.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.OrderService;
import com.sky.vo.OrderStatisticsVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //取消订单
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result putOrder(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderService.putOrder(ordersCancelDTO);
        return Result.success();
    }

    /*
    * 商家订单条件查询
    * */
    @GetMapping("/conditionSearch")
    public Result pageOrder(OrdersPageQueryDTO pageQueryDTO){
        PageResult pageResult = orderService.pageOrder(pageQueryDTO);
        return Result.success(pageResult);

    }

    /*
    * 商家接单
    * */
    @PutMapping("/confirm")
    public Result receiveOrder(@RequestBody OrdersConfirmDTO confirmDTO){
        Courier courier =orderService.receiveOrder(confirmDTO);
        return Result.success(courier);
    }

    /*
    * 根据路径ID查询
    * */
    @GetMapping("/details/{orderId}")
    public Result selectById(@PathVariable(name = "orderId") Long id){
       Orders orders = orderService.selectById(id);
        return Result.success(orders);

    }

    /*
    * 统计状态订单数量
    * */
    @GetMapping("/statistics")
    public Result orderStatusCount(){
        OrderStatisticsVO orderStatisticsVO=orderService.orderStatusCount();
        return Result.success(orderStatisticsVO);
    }
}
